'use strict'

let queryString = require('query-string');
let _ = require('lodash');
var Mock = require('mockjs');
var config = require('./config')

var request = {};

request.get = (url,params)=>{
  if(params){
    url += '?' + queryString.stringify(params);
  }
  return fetch(url)
      .then((response) => response.json())
      .then((response) =>  Mock.mock(response))
      .catch((error) => {
        console.log(44444)
        console.warn(error);
      });
}

request.post = (url,body)=>{
  var options = _.extend(config.headers,{
    method: 'POST',
    body: JSON.stringify(body)
  })
  return fetch(url)
      .then((response) => response.json())
      .then((response) =>  Mock.mock(response))
      .catch((error) => {
        console.warn(error);
      });
}

module.exports = request

